local songci = fk.CreateSkill {

  name = "joy__songci",

  tags = {  },

}



songci:addEffect("active", {
  name = "joy__songci",
  anim_type = "control",
  mute = true,
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    local mark = player:getTableMark(songci.name)
    return table.find(Fk:currentRoom().alive_players, function(p) return not table.contains(mark, p.id) end)
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected)
    local mark = player:getTableMark( songci.name)
    return #selected == 0 and not table.contains(mark, to_select)
  end,
  on_use = function(self, room, effect)
    local target = effect.tos[1]
    local player = effect.from
    local mark = player:getTableMark( songci.name)
    table.insert(mark, target.id)
    room:setPlayerMark(player, songci.name, mark)
    if #target.player_cards[Player.Hand] <= target.hp then
      room:notifySkillInvoked(player, songci.name, "support")
      player:broadcastSkillInvoke(songci.name, 1)
      target:drawCards(2, songci.name)
    else
      room:notifySkillInvoked(player, songci.name, "control")
      player:broadcastSkillInvoke(songci.name, 2)
      room:askForDiscard(target, 2, 2, true, songci.name, false)
    end
  end,
})

songci:addEffect(fk.EventPhaseEnd, {
  name = "#joy__songci_trigger",
  mute = true,
  --songci,
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    local mark = player:getTableMark( "joy__songci")
    return target == player and player:hasSkill(songci.name) and player.phase == Player.Discard
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:notifySkillInvoked(player, "joy__songci", "drawcard")
    player:broadcastSkillInvoke("joy__songci", 3)
    player:drawCards(1, "joy__songci")
  end,
})

return songci